<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\model\Weighbill as WM;
class Apps extends Controller
{
    public function getBase(){
        $data['status'] = 1;
        $data['msg'] = 'ok';
        $data['data']['houses'] = getHouseList();
        $data['data']['goods'] = goodsList();
        return $data;
    }
    public function adminDel(){
        $arr = input();
        if(!is_array($arr)){
            $data['status'] = -1;
            $data['msg'] = "条件为空";
            $data['data'] = $arr;
            return $data;
            exit;
        }
        $where = array();
        if(isset($arr['houseId']) && $arr['houseId'] > 0){
            $where['houseId'] = $arr['houseId'];
        }
        if(isset($arr['goodsName']) && $arr['goodsName'] != ""){
            $where['goodsName'] = $arr['goodsName'];
        }
        if(isset($arr['fullWeigh']) && $arr['fullWeigh'] > 30000){
            $where['fullWeigh'] = $arr['fullWeigh'];
        }else{
            $data['status'] = -1;
            $data['msg'] = "毛重错误，不能小于30000";
            $data['data'] = $arr;
            return $data;
            exit;
        }
        // if(isset($arr['startTime']) && $arr['startTime'] > 0){
        //     if(isset($arr['endTime']) && $arr['endTime']){
        //         $where['fullTime'] = "between " . $arr['startTime'] . " and " . $arr['endTime'];
        //     }else{
        //         $where['fullTime'] = ['>',$arr['startTime']];
        //     }
        // }
        // $data['status'] = 1;
        // $data['msg'] = "ok";
        // $data['data'] = $where;
        // return $data;
        // exit;
        $m = new WM();
        $list = $m->where($where)->find();
        if(empty($list)){
            $rs['status'] = -1;
            $rs['msg'] = '没有符合条件的的磅单';
            $rs['data'] = array();
            exit;
        }
        $rs = $m->where($where)->delete();
        if(empty($rs)){
            $data['status'] = -1;
            $data['msg'] = $m->getError();
            $data['data'] = '';
            return $data;
            exit;
        }
        $data['status'] = 1;
        $data['msg'] = "删除成功";
        $data['data'] = $rs;
        return $data;
    }
}
?>